import time
import random
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"./simhei.ttf")

c = [0,100,200,500,1000,1500]
t = [1652867870.3371859,1652867891.708318,1652867898.395279,1652867927.3051932,1652867954.7820888,1652867976.8738298]
### 三线程跑的数据
ttabs = [0.0, 21.371132135391235, 28.058093070983887, 56.9680073261261, 84.4449028968811, 106.5366439819336]
st = [1652870323.506046,1652870361.5947526,1652870381.5795348,1652870418.4499395,1652870685.3105218,1652871048.7110643]
## 单独的单线程跑的数据
stabs = [0.0, 38.088706493377686, 58.07348871231079, 167.94389343261719, 390.80447578430176, 725.2050182819366]
stabsraw = [0.0, 39.54735994159853, 59.61471352139115, 172.59593585543658, 401.9552053219238, 752.9672786484341]
plt.style.use('ggplot')
plt.figure(dpi=300).set_size_inches(8, 4)
l1 = plt.plot(c,stabs,'r--',label="1 spider")
l2 = plt.plot(c,ttabs,'g--',label="3 spiders")

plt.xlabel("抓取数据后存入数据库的数量（个）",fontproperties=font)
plt.ylabel("运行时间（秒）",fontproperties=font)
plt.title("单个爬虫和三个爬虫情况下对比",fontproperties=font)
plt.xticks(c)
plt.legend(loc = "best")
plt.savefig("./gen_multispiders.jpg")


plt.style.use('ggplot')
plt.figure(dpi=300).set_size_inches(8, 4)
l1 = plt.plot(c,stabs,'r--',label="Docker")
l2 = plt.plot(c,stabsraw,'g--',label="VM")

plt.xlabel("抓取数据后存入数据库的数量（个）",fontproperties=font)
plt.ylabel("运行时间（秒）",fontproperties=font)
plt.title("单个爬虫在裸机环境和Docker环境下对比",fontproperties=font)
plt.xticks(c)
plt.legend(loc = "best")
plt.savefig("./gen_st.jpg")